<template>
	<view>
		<view class="head">
			<view class="top"></view>
			<view class="list">
				<view :class="{'current':index==0}" @click="switchTo(0)">
					<view>
						<text>全部</text>
						<text></text>
					</view>
				</view>
			<!-- 	<view :class="{'current':index==1}" @click="switchTo(1)">
					<view>
						<text>晒图</text>
						<text>({{commImgCount}})</text>
					</view>
				</view> -->
				<view :class="{'current':index==2}" @click="switchTo(2)">
					<view>
						<text>最新</text>
						<text></text>
					</view>
				</view>
			</view>
			
		</view>
		<view class="content">
			<view class="evaluate" v-for="item in EvaluateData">
				<view class="up">
					<view class="user">
						<image class="img" mode="" :src="item.headPortrait"></image>
						<view class="text">
							<view class="name">{{item.name}}</view>
							<view class="graded" >
								<view class="" v-for="i in 5">
									<image src="@/static/star/StarEvaluation1.png" v-if="i>item.describe_grade"></image>
									<image src="@/static/star/StarEvaluation2.png" v-else></image>
								</view>
							</view>
						</view>
					</view>
					<view class="time">{{getDateymd(item.creation_time)}}</view>
				</view>
				<view class="bottom">
					<view class="text">{{item.text}}</view>
					<view class="imgs">
						<image :src="setEvaluate_img(img)" @click="previewImage1(setEvaluate_img(img))" v-for="img in item.imgs"></image>
					
						
					</view>
				</view>
				
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				index:0,
				EvaluateData:[],//评价数据
				commImgCount:0,//有图片评价数量
				commodity_id:0//商品id
			}
		},
		onLoad(e) {
			this.commodity_id = e.id
			this.getEvaluates();
		},
		onReachBottom() {
			this.getEvaluates();
		},
		methods: {
			previewImage1(imgUrl) {
				var imgUrls = [imgUrl]
				uni.previewImage({
					current: imgUrl,
					urls: imgUrls
				});
			},
			getEvaluates(){
				uni.showLoading({
					title: '请稍等',
					mask: true
				})
				this.$http('goods.getEvaluates',{
					commodity_id:this.commodity_id,
					page:this.EvaluateData.length,
					type:this.index
				}).then(res=>{
						var  code = res.code
						if(code==200){
							this.commImgCount = res.data.commImgCount;
							var evaluates = res.data.evaluates;
							for (let var1 in evaluates) {
								evaluates[var1].imgs = JSON.parse(evaluates[var1].imgs)
								this.EvaluateData.push(evaluates[var1]);
							}
						}else{
							uni.showToast({
								title: res.msg,
								icon:"none"
							})
						}
				})
			},
			switchTo(index){
				this.index = index;
				this.EvaluateData = [];
				this.getEvaluates();
			}
			
		}
	}
</script>

<style>
	.top{
		border-top: 1px solid #EEEEEE;
		width: 100vw;
		position:  fixed;
		
		/* #ifdef  H5 */
		top: 88upx;
		/* #endif */
		/* #ifdef MP-WEIXIN */
		top: 0upx;
		/* #endif */
		z-index: 11;
	}
	.head{
		background-color: #FFFFFF;
		position:  fixed;
		
		width: 100vw;
		background-color: #FFFFFF;
		z-index: 11;
		
		/* #ifdef  H5 */
		top: 90upx;
		/* #endif */
		/* #ifdef MP-WEIXIN */
		top: 0upx;
		/* #endif */
	}
	.head .list{
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		font-size: 16px;
		
		border-bottom: 1px solid #FAFAFA;
	}
	.head .list >view{
		padding: 20upx 0upx;
	}
	.head .list .current{
		border-bottom: 4upx #FA436A solid;
		color: #FA436A;
	}
	.content{
		margin-top: 90upx;
		
	}
	.evaluate{
		border-bottom: 1px solid #FAFAFA;
		padding: 20upx;
	}
	.evaluate .up{
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}
	.evaluate .up .user {
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.evaluate .up .user .text{
		font-size: 16px;
		color: #555555;
	}
	.evaluate .up .user .img{
		width: 90upx;
		height: 90upx;
		border-radius: 45upx;
		margin-right: 20upx;
		
	}
	.evaluate .up .user .text .graded{
		font-size: 14px;
		color: #262626;
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.evaluate .up .user .text .graded >view{
		font-size: 14px;
		color: #262626;
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.evaluate .up .user .text .graded >view >image{
		width: 28upx;
		height: 28upx;
		
	}
	.evaluate .up .time{
		font-size: 14px;
		color: #888888;
	}
	.evaluate .bottom{
		font-size: 16px;
		margin-top: 10upx;
		margin-left: 110upx;
	}
	.evaluate .bottom .imgs{
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
	}
	.evaluate .bottom .imgs >image{
		width: 192upx;
		height: 192upx;
		margin-right: 8upx;
		margin-top: 8upx;
	}
</style>
